package terms;

public class ArrayGraph extends AbstractGraph {

	private Gain[][] data;

	public ArrayGraph(int size) {
		super(size);
		this.size = size;
		data = new Gain[size][size];
	}

	@Override
	public Gain get(int i, int j) {
		return data[i][j];
	}

	@Override
	public void put(int i, int j, Gain element) {
		data[i][j] = element;
		element.setFrom(i);
		element.setTo(j);
	}

	/**
	 * @return an array containing all next elements indices exclusively
	 */
	@Override
	public int[] execlusiveNext(int e) {
		int[] d = new int[size];
		int len = 0;
		for (int i = 0; i < size; i++) {
			if (i == e)
				continue;
			if (data[e][i] != null)
				d[len++] = i;
		}
		int[] real = new int[len];
		for (int i = 0; i < len; i++) {
			real[i] = d[i];
		}
		return real;
	}
	
}
